<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增项目计划')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-plan-add">
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">计划表名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="planName" id="planName" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">排序：</label>
            <div class="col-sm-3">
                <select id="sort" name="sort" class="form-control">
                    <option value="A">A</option>
                    <option value="B">B</option>
                    <option value="C">C</option>
                    <option value="D">D</option>
                </select>
            </div>
            <label class="col-sm-2 control-label is-required">课程类型：</label>
            <div class="col-sm-3">
                <select id="courseId" name="courseId" class="form-control">
                    <option value="28">运动力课程</option>
                    <option value="29">感知觉课程</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">年龄年级段：</label>
            <div class="col-sm-3">
                <select name="ageGrade" id="ageGrade" class="form-control"
                        th:with="type=${@dict.getType('age_grade')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}">
                    </option>
                </select>
            </div>
            <label class="col-sm-2 control-label is-required">班级类型：</label>
            <div class="col-sm-3">
                <select id="classType" name="classType" class="form-control">
                    <option value="1">常规班</option>
                    <option value="2">集训班</option>
                </select>
            </div>
        </div>
        <div class="form-group">

            <label class="col-sm-2 control-label is-required">总课节数：</label>
            <div class="col-sm-3">
                <input class="form-control" type="text" name="totalClassTimes" id="totalClassTimes" required>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
    // 字典
    var prefix = ctx + "business/classPlan";

    $("#form-plan-add").validate({
        onkeyup: false,
        rules:{
            planName:{
                remote: {
                    url: prefix + "/checkPlanNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "planName": function() {
                            return $.common.trim($("#planName").val());
                        },
                        "ageGrade":$("#ageGrade").val()
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            }
        },
        messages: {
            "planName": {
                remote: "计划名称已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            add();
        }
    }
    function add() {
        $.ajax({
            cache: true,
            type: "POST",
            url: prefix + "/add",
            data: {
                "planName": $("#planName").val(),
                "sort": $("#sort").val(),
                "courseId": $("#courseId").val(),
                "age": $("#age").val(),
                "grade": $("#grade").val(),
                "ageGrade": $("#ageGrade").val(),
                "classType": $("#classType").val(),
                "totalClassTimes": $("#totalClassTimes").val()
            },
            async: false,
            error: function (request) {
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                $.operate.successCallback(data);
            }
        });
    }
</script>
</body>
</html>
